
class Tabs{
    constructor(selector,options){
        this.ele = document.querySelector(selector);
        this.btns = this.ele.querySelectorAll('ul > li');
        this.contents = this.ele.querySelectorAll('ol > li');
        this.options = options || {}; // 如果没传实参 那么把一个空对象给到 this.options
        this.init(); // 实例化对象 直接调用自己的init方法
    }

    init(){
        let mybtns =  this.btns;
        let myconents =  this.contents;

        for(let i=0;i<this.btns.length;i++){
            this.btns[i].addEventListener(this.options.type || 'click',function(){
                for(let j=0;j<mybtns.length;j++){
                    mybtns[j].classList.remove('active');
                    myconents[j].classList.remove('active');
    
                }
                mybtns[i].classList.add('active');
                myconents[i].classList.add('active');

            })
        }
    }

}